<?php
 /******************************************************************************
 *   GunCMS is an avid supporter of open source software. This is the appropriate 
 *   option if you are creating an open source application with a license 
 *   compatible with the GNU GPL license v3.
 *   For details http://www.gnu.org/licenses/gpl.html
 *   DO NOT USE FOR COMMERCIAL WITHOUT PERMISSION
 *
 * GunCMS Version 1.0.3
 * Copyright(c) 2009-2010, T & L GdbR
 * info@guncms.de
 * 
 * http://www.guncms.de
 ********************************************************************************/
global $root_path;
define("APP_DIR", $root_path . "/");
require 'libraries/smarty/libs/Smarty.class.php';

class MySmarty extends smarty {
  function MySmarty() {
    $this->template_dir    =  APP_DIR . 'view' . '/' . TEMPLATE_NAME;
    $this->compile_dir     =  APP_DIR . 'view_c' . '/' . TEMPLATE_NAME;
    $this->config_dir      =  APP_DIR . 'configs';
    $this->cache_dir      =  APP_DIR . 'cache';
    
    $this->compile_check = true;
    $this->debugging = false;
    $this->caching = false;
  }
}

$smarty = new MySmarty();

function eval_buffer($string) {
    ob_start();
    eval("$string[2];");
    $ret = ob_get_contents();
    ob_end_clean();
    return $ret;
}

function eval_html($string)  {
    return preg_replace_callback("/(<\?php|<\?)(.*?)\?>/si", "eval_buffer",$string);
} 


function smarty_eval($params) { 
	if(!empty($params['code'])) { 
	    $content = $params['code']; 
	    //execute php code if any
		$trans = array("&lt;?php" => "[php]", "?&gt;" => "[/php]");
		$content = strtr($content, $trans);
		
		$trans = array("<php>" => "<?php", "</php>" => "?>");
		$content = strtr($content, $trans);
		
		$content = html_entity_decode($content, ENT_QUOTES);
		$content = eval_html($content);
		
		$trans = array("[php]" => "&lt;?php", "[/php]" => "?&gt;");
		$content = strtr($content, $trans);
		
		return $content; 
	} 
} 

$smarty->register_function("smarty_eval", "smarty_eval"); 

?>